package com.xujiang.imitationcompanypj.data.net;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.jackson.JacksonConverterFactory;

/**
 * Created by xujiang on 2017/4/5.
 */

public class RetrofitUtils {
    private RetrofitUtils(){

    }

    private static RetrofitUtils retrofitUtils;

    public static  RetrofitUtils get(){
        if(retrofitUtils == null){
            retrofitUtils = new RetrofitUtils();
        }
        return retrofitUtils;
    }

    Retrofit mRetrofit;
    Retrofit.Builder mRetrofitBuilder;
    Retrofit.Builder mRetrofitBaseUrlBuilder;

    public void init(String baseUrl, OkHttpClient client){
        mRetrofitBaseUrlBuilder = new Retrofit.Builder().baseUrl(baseUrl).client(client);
        mRetrofitBuilder = mRetrofitBaseUrlBuilder.addConverterFactory(JacksonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create());
        mRetrofit = mRetrofitBuilder.build();
    }

    private  UserService mUserService;

    public UserService getmUserService(){
        if(mUserService == null){
            mUserService = RetrofitUtils.get().getRetrofit().create(UserService.class);
        }
        return mUserService;
    }


    public Retrofit.Builder getRetrofitBuilder(){
        return mRetrofitBuilder;
    }
    public Retrofit.Builder getRetrofitBaseUrlBuilder(){
        return mRetrofitBaseUrlBuilder;
    }

    public Retrofit getRetrofit(){
        return mRetrofit;
    }




}
